package test.san.baseproject.ui.fragment

import android.util.Log
import android.view.View
import android.widget.Toast
import kotlinx.android.synthetic.main.mv_fragment.*
import test.san.baseproject.R
import test.san.baseproject.adapter.MvPageAdapter
import test.san.baseproject.base.BaseFragmnet
import test.san.baseproject.model.AreaBeam
import test.san.baseproject.presenter.impl.MvPresenterImp
import test.san.baseproject.view.MvView

class MVFragment: BaseFragmnet(), MvView {

    override fun onError(msg: String?) {
        Log.e("${this.javaClass.name}", "获取数据失败" )
    }

    override fun onSuccess(result: List<AreaBeam>?) {
        val name = this.javaClass.name
        Log.e("${name}", "获取数据成功" )

        // 在fragmet中管理需要用childFragmentManager
        val pageAdapter = MvPageAdapter(result, childFragmentManager)
        viewpager.adapter = pageAdapter

        tablayout.setupWithViewPager(viewpager)
    }

    private val mvPresenter by lazy { MvPresenterImp(this) }

    override fun initView(): View? {
        val textView = View.inflate(context, R.layout.mv_fragment, null)
        return textView
    }


    override fun initLister() {

    }


    override fun initData() {
        // 加载区域数据
        mvPresenter.loadDatas()
    }
}